﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Wentong300Cameral
{
    class ipcsdk
    {
        [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.StdCall)]
        /**
         *  @brief  通过该回调函数获得实时识别数据
         *  @param  [OUT] pvParam	         用户自定义参数，用来区分不同的sdk使用者，类似于线程入口函数的参数（与设置此回调接口的最后一个参数相同）
         *  @param  [OUT] pcIP	             相机ip
         *  @param  [OUT] pcNumber           车牌号	
         *  @param  [OUT] pcColor            车牌颜色（"蓝色","黄色","白色","黑色",“绿色”）
         *  @param  [OUT] pcPicData          全景数据
         *  @param  [OUT] u32PicLen          全景数据长度
         *  @param  [OUT] pcCloseUpPicData   车牌数据
         *  @param  [OUT] u32CloseUpPicLen   车牌数据长度
         *  @param  [OUT] nSpeed             车辆速度
         *  @param  [OUT] nVehicleType       车辆类型（0:未知,1轿车,2面包车,3大型客车,4中型客车,5皮卡,6非机动车,7SUV,8MPV,9微型货车,10轻型货车,11中型货车,12重型货车)
         *  @param  [OUT] s16FalsePlate      虚假车牌（0:否，1是)
         *  @param  [OUT] nReserved2         预留参数2
         *  @param  [OUT] fPlateConfidence   车牌打分值（SDK输出的范围大于IE界面设置的车牌阈值，上限是28，例如：IE设置的是10，范围：10-28）
         *  @param  [OUT] u32VehicleColor    车身颜色（车辆特征码相机版本：(-1:未知,0:黑色,1:蓝色,2:灰色,3:棕色,4:绿色,5:夜间深色,6:紫色,7:红色,8:白色,9:黄色)
         *                                           其它相机版本：(0:未知,1:红色,2:绿色,3:蓝色,4:黄色,5:白色,6:灰色,7:黑色,8:紫色,9:棕色,10:粉色)）
         *  @param  [OUT] u32PlateType       车牌类型，详见车牌类型ICE_PLATETYPE_E枚举值
         *  @param  [OUT] u32VehicleDir      车辆方向（0:车头方向,1:车尾方向,2:车头和车尾方向）
         *  @param  [OUT] u32AlarmType       报警输出，详见报警输出ICE_VDC_ALARM_TYPE枚举值
         *  @param  [OUT] u32SerialNum       抓拍的序号（从相机第一次抓拍开始计数，相机重启后才清零）
         *  @param  [OUT] uCapTime           实时抓拍时间，从1970年1月1日零点开始的秒数
         *  @param  [OUT] u32ResultHigh      车牌识别数据结构体（ICE_VDC_PICTRUE_INFO_S）指针高8位（64位sdk时需要使用）
         *  @param  [OUT] u32ResultLow       车牌识别数据结构体（ICE_VDC_PICTRUE_INFO_S）指针低8位
         *  @return void
         */
        public delegate void ICE_IPCSDK_OnPlate(
                    System.IntPtr pvParam,
                    [System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string pcIP,
                    [System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string pcNumber,
                    [System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string pcColor,
                    System.IntPtr pcPicData,
                    uint u32PicLen,
                    System.IntPtr pcCloseUpPicData,
                    uint u32CloseUpPicLen,
                    short nSpeed,
                    short nVehicleType,
                    short s16FalsePlate,
                    short nReserved2,
                    float fPlateConfidence,
                    int u32VehicleColor,
                    uint u32PlateType,
                    uint u32VehicleDir,
                    uint u32AlarmType,
                    uint u32SerialNum,
                    uint uCapTime,
                    uint u32ResultHigh,
                    uint u32ResultLow);

        /**
         *  @brief  设置获得实时识别数据的相关回调函数
         *  @param  [IN] hSDK       连接相机时返回的sdk句柄
         *  @param  [IN] pfOnPlate  实时识别数据，通过该回调获得
         *  @param  [IN] pvParam    回调函数中的参数，能区分开不同的使用者即可
         *  @return void
         */
        [System.Runtime.InteropServices.DllImportAttribute("ice_ipcsdk.dll", EntryPoint = "ICE_IPCSDK_SetPlateCallback", CallingConvention = CallingConvention.Cdecl)]
        public static extern void ICE_IPCSDK_SetPlateCallback(System.IntPtr hSDK, ICE_IPCSDK_OnPlate pfOnPlate, System.IntPtr pvParam);

        /**
        *  @brief  全局初始化
        *  @return void
        */
        [System.Runtime.InteropServices.DllImportAttribute("ice_ipcsdk.dll", EntryPoint = "ICE_IPCSDK_Init", CallingConvention = CallingConvention.Cdecl)]
        public static extern void ICE_IPCSDK_Init();

        /**
        *  @brief  全局释放
        *  @return void
        */
        [System.Runtime.InteropServices.DllImportAttribute("ice_ipcsdk.dll", EntryPoint = "ICE_IPCSDK_Fini", CallingConvention = CallingConvention.Cdecl)]
        public static extern void ICE_IPCSDK_Fini();

        /**
         *  @brief  连接相机，不带视频流
         *  @param  [IN] pcIP   相机ip
         *  @return sdk句柄(连接不成功时，返回值为null）
         */
        [System.Runtime.InteropServices.DllImportAttribute("ice_ipcsdk.dll", EntryPoint = "ICE_IPCSDK_OpenDevice", CallingConvention = CallingConvention.Cdecl)]
        public static extern System.IntPtr ICE_IPCSDK_OpenDevice([System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string pcIP);

        /**
         *  @brief  断开连接
         *  @param  [IN] hSDK   连接相机时返回的句柄值
         *  @return void
         */
        [System.Runtime.InteropServices.DllImportAttribute("ice_ipcsdk.dll", EntryPoint = "ICE_IPCSDK_Close", CallingConvention = CallingConvention.Cdecl)]
        public static extern void ICE_IPCSDK_Close(System.IntPtr hSDK);

        /**
        *  @brief  打开道闸
        *  @param  [IN] hSDK  SDK句柄
        *  @return 1 成功 0 失败
        */
        [System.Runtime.InteropServices.DllImportAttribute("ice_ipcsdk.dll", EntryPoint = "ICE_IPCSDK_OpenGate", CallingConvention = CallingConvention.Cdecl)]
        public static extern uint ICE_IPCSDK_OpenGate(System.IntPtr hSDK);

        /**
         *  @brief  连接视频
         *  @param  [IN] hSDK           连接相机时返回的句柄值
         *  @param  [IN] u8MainStream   是否请求主码流（1：主码流 0：子码流）
         *  @param  [IN] hWnd           预览视频的窗口句柄
         *  @return 1表示成功，0表示失败
         */
        [System.Runtime.InteropServices.DllImportAttribute("ice_ipcsdk.dll", EntryPoint = "ICE_IPCSDK_StartStream", CallingConvention = CallingConvention.Cdecl)]
        public static extern uint ICE_IPCSDK_StartStream(System.IntPtr hSDK, byte u8MainStream, uint hWnd);

        /**
         *  @brief  断开视频
         *  @param  [IN] hSDK   连接相机时返回的句柄值
         *  @return void
         */
        [System.Runtime.InteropServices.DllImportAttribute("ice_ipcsdk.dll", EntryPoint = "ICE_IPCSDK_StopStream", CallingConvention = CallingConvention.Cdecl)]
        public static extern void ICE_IPCSDK_StopStream(System.IntPtr hSDK);

        /**
         *  @brief  软触发扩展接口
         *  @param  [IN]  hSDK          由连接相机接口获得的句柄
         *  @return 1表示成功，0表示失败
         */
        [System.Runtime.InteropServices.DllImportAttribute("ice_ipcsdk.dll", EntryPoint = "ICE_IPCSDK_TriggerExt", CallingConvention = CallingConvention.Cdecl)]
        public static extern uint ICE_IPCSDK_TriggerExt(System.IntPtr hSDK);

        public delegate void ICE_IPCSDK_OnDeviceEvent(System.IntPtr pvParam,
            [System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string pcIP,
            uint u32EventType, uint u32EventData1, uint u32EventData2, uint u32EventData3, uint u32EventData4);

        [System.Runtime.InteropServices.DllImportAttribute("ice_ipcsdk.dll", EntryPoint = "ICE_IPCSDK_SetDeviceEventCallBack", CallingConvention = CallingConvention.Cdecl)]
        public static extern void ICE_IPCSDK_SetDeviceEventCallBack(System.IntPtr hSDK, ICE_IPCSDK_OnDeviceEvent pfOnDeviceEvent, System.IntPtr pvDeviceEventParam);

        /**
         *  @brief  发送RS485串口数据
         *  @param  [IN] hSDK      由连接相机接口获得的句柄
         *  @param  [IN] pcData    RS485串口数据
         *  @param  [IN] u32Len    串口数据长度
         *  @return 1表示成功，0表示失败
         */
        [System.Runtime.InteropServices.DllImportAttribute("ice_ipcsdk.dll", EntryPoint = "ICE_IPCSDK_TransSerialPort", CallingConvention = CallingConvention.Cdecl)]
        //public static extern uint ICE_IPCSDK_TransSerialPort(System.IntPtr hSDK, String pcData, uint u32Len);
        public static extern uint ICE_IPCSDK_TransSerialPort(System.IntPtr hSDK, byte[] pcData, uint u32Len);
    }
}
